package exabase;

import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;

import exabase.com.Com;

public class Exabase {
	private static Logger logger = Logger.getLogger(Exabase.class.getName());
	protected static Exabase instance = null;

	protected Exabase() {
		String logfile = null;
		try {
			int i = 1;
			logfile = "log" + i + ".xml";
			while (new File(logfile).exists()) {
				++i;
				logfile = "log" + i + ".xml";
				if (i > 200)
					logfile = "log.xml";
			}
			FileHandler handler = new FileHandler("log" + i + ".xml");
			Logger logger = Logger.getLogger("exabase");
			logger.setLevel(Level.ALL);
			logger.addHandler(handler);
		} catch (SecurityException e) {
			logger.log(Level.WARNING, "Error", e);
		} catch (IOException e) {
			logger.log(Level.WARNING, "Error", e);
		}

		logger.fine("Constructor. Instantiating layers. Logging to " + logfile
				+ ".");
	}

	public static Exabase getInstance() {
		if (instance == null) {
			instance = new Exabase();
		}
		return instance;
	}

	public void go() {
		logger.fine("Exabase is go!");
		Com.getInstance().go();
	}

	public static void main(String[] args) {
		Exabase.getInstance().go();
	}

}
